import {axios} from "../utils/request";
import global from "../store/global";

const api = global.serverAddress + "/file";

//根据文件名下载文件
export function getFileAPI(fileName) {
    return axios({
        url: `${api}/download`,
        method: "GET",
        data: fileName
    });
}

// 查看oss桶中的所有图片
export function getFileListAPI() {
    return axios({
        url: `${api}/list`,
        method: "GET"
    });
}

// oss根据fileName删除图片，数据库通过id删除图片记录
export function deleteFileAPI(params) {
    return axios({
        url: `${api}/delete/${params.nodeId}`,
        method: "POST",
        data: params.fileName
    });
}

// 图片上传到阿里云oss服务器，上传成功会返回图片url
export function uploadPictureAPI(params) {
    return axios({
        url: `${api}/upload/${params.graphId}/${params.nodeId}`,
        method: "POST",
        data: params.file
    });
}

// 上传头像
export function uploadAvatarAPI(params) {
    return axios({
        url: `${api}/upload/avatar/${params.id}`,
        method: "POST",
        data: params.file
    });
}

// 上传封面
export function uploadGraphCoverAPI(params) {
    return axios({
        url: `${api}/upload/graph/${params.id}`,
        method: "POST",
        data: params.file
    });
}